/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.fyx.secure.web.user;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.fyx.secure.entity.SecureUser;
import org.fyx.secure.ejb.SecureLocal;
import org.fyx.secure.ejb.SecureRoles;
import org.fyx.util.FyxUtility;

/**
 *
 * @author xljan
 */
@ManagedBean
@RequestScoped
public class SecureUserList {

    @EJB
    private SecureLocal secure;
    private SecureUser user = new SecureUser();

    @PostConstruct
    public void postConstruct(){
        FyxUtility.checkRole(SecureRoles.USER_MANAGER);
    }

    public void setUser(SecureUser user) {
        this.user = user;
    }

    public SecureUser getUser() {
        return user;
    }

    public SecureUser getUserById(int idUser){
        return secure.getUserById(idUser);
    }

    public void create() {
        secure.addUser(user);
    }

    public void remove() {
        if (user != null) {
            secure.deleteUser(user);
        }
    }

    public int getCount(){
        return secure.getCountUsers();
    }
}
